#define DEBUG
#include <cstdio>

using namespace std;

const int mods=998244353;

int main() {
  freopen("pair.in", "r", stdin);
  freopen("pair.out", "w", stdout);

  int t, id;
  scanf("%d %d", &t, &id);
  for (int ti=1; ti<=t; ti++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);

    int cnt=0;
    for (long long i=l; i<=r; i++) {
      for (long long j=1; j<=i; j*=10) {
	for (long long k=1; k<j; k*=10) {
	  if (i/j%10>i/k%10) {
	    cnt++;
	  }
	}
      }
    }
    printf("%d\n", cnt);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
